from Crypto.PublicKey import RSA


def CreateRSAKeys():
    code = 'nooneknows'
    # 生成 2048 位的 RSA 密钥
    key = RSA.generate(2048)
    encrypted_key = key.exportKey(passphrase=code, pkcs=8, protection="scryptAndAES128-CBC")
    # 生成私钥
    with open('zmy_rsa', 'wb') as f:
        f.write(encrypted_key)
    # 生成公钥
    with open('zmy_rsa.pub', 'wb') as f:
        f.write(key.publickey().exportKey())


CreateRSAKeys()
